/*$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'dictionary/dictionary/searchQuery'+vm.requestParameter(),
        datatype: "json",
        colModel: [
            { label: '数据字典ID', name: 'dictionaryid', index: 'DictionaryId', width: 50, key: true },
            { label: '字典类型', name: 'typename', index: 'TypeName', width: 80 },
            { label: '数据类型名称', name: 'datatypename', index: 'DataTypeName', width: 80 },
            { label: '字典内容', name: 'dictionaryvalue', index: 'DictionaryValue', width: 80 },
            { label: '字典中文内容', name: 'dictionaryvalueinzhcn', index: 'DictionaryValueInZhCN', width: 80 },
            { label: '序号', name: 'optionorder', index: 'OptionOrder', width: 50 },
            { label: '创建时间', name: 'createtime', index: 'CreateTime', width: 90 },
            { label: '更新时间', name: 'updatetime', index: 'UpdateTime', width: 90 },
            { label: '软删除', name: 'isdel', index: 'IsDel', width: 50 , formatter: function(value, options, row){
                    return value === 0 ?
                        '<span class="label label-success">正常</span>' :
                        '<span class="label label-danger">已删除</span>';
                }},
            { label: '是否只读', name: 'isreadonly', index: 'IsReadOnly', width: 40, formatter: function(value, options, row){
                    return value === 0 ?
                        '<span class="label label-success">可写</span>' :
                        '<span class="label label-danger">只读</span>';
                } }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
            localStorage.removeItem("typename");
        }
    });
});*/

var vm = new Vue({
    el:'#rrapp',
    data:{
        showList: true,
        showReleaseIntegral:true,
        showBrowseIntegral:true,
        showIntegralNumber:true,
        showVipDiscount:true,
        showDiscount:true,
        title: null,
        integralConfiguration:{},
        integralSetting:{},
        dictionary:{}

    },
    beforeMount:function () {
        //初始积分
        $.ajax({
            type: "GET",
            url: baseURL + 'dictionary/dictionary/queryIntegralConfiguration',
            contentType: "application/json",
            success: function(r){
                if(r.code === 0){
                    vm.integralConfiguration = r.data;
                }
            }
        });
    }
    ,
    methods: {
        updateDiscounts:function (dateTypeName) {
            if (dateTypeName == "VIPDiscount"){
                vm.dictionary.dictionaryvalue = vm.integralSetting.vipdiscount;
                vm.dictionary.datatypename = "VIPDiscount";
            }else if(dateTypeName == "Discount"){
                vm.dictionary.dictionaryvalue = vm.integralSetting.discount;
                vm.dictionary.datatypename = "Discount";
            }else {
                return;
            }
            $.ajax({
                type: "POST",
                url: baseURL + 'pointmanagement/pointmanagement/updateIntegral',
                data:JSON.stringify(vm.dictionary),
                contentType: "application/json",
                success: function(r){
                    if(r.code === 0){
                        if (dateTypeName == "VIPDiscount"){
                            vm.integralConfiguration.vipdiscount = vm.integralSetting.vipdiscount;
                            vm.showVipDiscount = true;
                        }else if(dateTypeName == "Discount"){
                            vm.integralConfiguration.discount = vm.integralSetting.discount;
                            vm.showDiscount = true;
                        }
                        vm.integralSetting = {};
                        alert("修改成功");
                    }else {
                        alert(r.msg);
                    }
                }

            });
        },
        updateInitIntegral:function () {
            vm.dictionary.dictionaryvalue = vm.integralSetting.integralnumber;
            vm.dictionary.datatypename = "IntegralNumber";
            $.ajax({
                type: "POST",
                url: baseURL + 'pointmanagement/pointmanagement/updateIntegral',
                data:JSON.stringify(vm.dictionary),
                contentType: "application/json",
                success: function(r){
                    if(r.code === 0){
                        vm.integralConfiguration.integralnumber = vm.integralSetting.integralnumber;
                        vm.showIntegralNumber = true;
                        vm.integralSetting = {};
                        alert("修改成功");
                    }else {
                        alert(r.msg);
                    }
                }

            });
        },
        updateIntegral:function (dateTypeName) {
            if (dateTypeName == "BrowseIntegral"){
                vm.dictionary.dictionaryvalue = vm.integralSetting.browseintegral;
                vm.dictionary.datatypename = "BrowseIntegral";
            }else if(dateTypeName == "ReleaseIntegral"){
                vm.dictionary.dictionaryvalue = vm.integralSetting.releaseintegral;
                vm.dictionary.datatypename = "ReleaseIntegral";
            }else {
                return;
            }
                $.ajax({
                    type: "POST",
                    url: baseURL + 'pointmanagement/pointmanagement/updateIntegral',
                    data:JSON.stringify(vm.dictionary),
                    contentType: "application/json",
                    success: function(r){
                        if(r.code === 0){
                            if (dateTypeName == "BrowseIntegral"){
                                vm.integralConfiguration.browseintegral = vm.integralSetting.browseintegral;
                                vm.showBrowseIntegral = true;
                            }else if(dateTypeName == "ReleaseIntegral"){
                                vm.integralConfiguration.releaseintegral = vm.integralSetting.releaseintegral;
                                vm.showReleaseIntegral = true;
                            }
                            vm.integralSetting = {};
                            alert("修改成功");
                        }else {
                            alert(r.msg);
                        }
                    }

            });
        },
        add: function(){
           /* vm.showList = false;
            vm.title = "新增";
            vm.dictionary = {
                isdel:'0',
            };*/
        },
        update: function (event) {
           /* var dictionaryid = getSelectedRow();
            if(dictionaryid == null){
                return ;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(dictionaryid)*/
        },
        saveOrUpdate: function (event) {
           /* var url = vm.dictionary.dictionaryid == null ? "dictionary/dictionary/save" : "dictionary/dictionary/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.dictionary),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });*/
        },
        del: function (event) {
           /* var dictionaryids = getSelectedRows();
            if(dictionaryids == null){
                return ;
            }

            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "dictionary/dictionary/delete",
                    contentType: "application/json",
                    data: JSON.stringify(dictionaryids),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(index){
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });*/
        },
        getInfo: function(dictionaryid){
            /*$.get(baseURL + "dictionary/dictionary/info/"+dictionaryid, function(r){
                vm.dictionary = r.dictionary;
            });*/
        },
        reload: function (event) {
           /* vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                url:baseURL + 'dictionary/dictionary/searchQuery'+((vm.typename != null)? "?typename="+vm.typename : ""),
                postData:{"typename":vm.typename},
                page:page
            }).trigger("reloadGrid");
            vm.typename = null;*/
        }
    }
});